/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.eweboffice;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.eweboffice.DocumentProc;
import com.unis.service.eweboffice.DocumentProcService;

/**
 * @author CSJ (email:Cao.shengjie777@gmail.com)
 * @since 2013-04-09
 */
@Controller
@RequestMapping("/documentproc")
public class DocumentProcController {

    private DocumentProcService documentprocService;

    /****************************************
     * Insert a instace of DocumentProc
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertDocumentProc(@RequestBody DocumentProc documentproc) throws Exception {
        documentproc.setStatmentId("DocumentProc.insert");
        String status = "failure";
        documentprocService.insert(documentproc);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of DocumentProc
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody DocumentProc documentproc) throws Exception {
        documentproc.setStatmentId("DocumentProc.update");
        String status = "failure";
        documentprocService.update(documentproc);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of DocumentProc
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody DocumentProc documentproc) throws Exception {
        documentproc.setStatmentId("DocumentProc.delete");
        String status = "failure";
        documentprocService.batchDelete(documentproc);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of DocumentProc
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        DocumentProc documentproc = new DocumentProc();
        documentproc.setStatmentId("DocumentProc.queryAsList");
        BeanUtils.populate(documentproc, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(documentproc, pageMap);
        List<BaseModel> documentprocList = documentprocService.queryAsList(documentproc);
        Map<String, Object> renderMap = GridUIMapper.render(documentproc, documentprocList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of DocumentProc
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody DocumentProc documentproc) throws Exception {
        documentproc.setStatmentId("DocumentProc.queryAsObject");
        return documentprocService.queryAsObject(documentproc);
    }

    @RequestMapping("/page")
    public String forword() {
        return "eweboffice/documentprocList";
    }

    @Resource
    public void setDocumentProcService(DocumentProcService documentprocService) {
        this.documentprocService = documentprocService;
    }
}
